home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / dpms-standby < prev    next >
Encoding:
Text File  |  2012-05-20  |  2.1 KB  |  67 lines

  1. #! /bin/sh
  2. #
  3. # Laptop mode tools module: control X display standby / suspend / off using DPMS
  4. #
  5.  
  6. # getXuser gets the X user belonging to the display in $displaynum.
  7. # (This code was borrowed from the Debian acpi-support package.)
  8. getXuser() {
  9.     user=`w -hs | awk '{ if ($3 == ":'$displaynum'" || $3 ~ /:'$displaynum'\..*/ || $2 == ":'$displaynum'" || $2 ~ /:'$displaynum'\..*/) { print $1; exit; } }'`
  10.     if [ x"$user" = x"" ]; then
  11.         startx=`pgrep -n startx`
  12.         if [ x"$startx" != x"" ]; then
  13.             user=`ps -o user --no-headers $startx`
  14.         fi
  15.     fi
  16.     if [ x"$user" != x"" ]; then
  17.             userhome=`getent passwd $user | cut -d: -f6`
  18.             export XAUTHORITY=$userhome/.Xauthority
  19.     else
  20.         export XAUTHORITY=""
  21.     fi
  22.     export XUSER=$user
  23. }
  24.  
  25.  
  26. # Set X screen standby/suspend/powerdown timing
  27. if [ x$CONTROL_DPMS_STANDBY = x1 ]  || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_DPMS_STANDBY = xauto ]; then
  28.     if [ $ON_AC -eq 1 ]; then
  29.         if [ "$ACTIVATE" -eq 1 ]; then
  30.             STANDBY="$LM_AC_DPMS_STANDBY"
  31.             SUSPEND=$(($STANDBY+30))
  32.             OFF=$(($STANDBY+60))
  33.         else
  34.             STANDBY="$NOLM_AC_DPMS_STANDBY"
  35.             SUSPEND=$(($STANDBY+300))
  36.             OFF=$(($STANDBY+600))
  37.         fi
  38.     else
  39.         STANDBY="$BATT_DPMS_STANDBY"
  40.         SUSPEND=$(($STANDBY+30))
  41.         OFF=$(($STANDBY+60))
  42.     fi
  43.  
  44.     # Loop through all X servers using their unix domain sockets.
  45.     # (Partly borrowed from the Debian acpi-support package.)
  46.     for x in /tmp/.X11-unix/*; do
  47.         if [ -e "$x" ] ; then
  48.             displaynum=`echo $x | sed -r 's#/tmp/.X11-unix/X([0-9]*)$#\1#'`
  49.             log "VERBOSE" "Determining Xauthority for display $displaynum"
  50.             getXuser;
  51.             if [ x"$XAUTHORITY" != x"" ]; then
  52.                 export DISPLAY=":$displaynum"        
  53.                 if su $XUSER -c "xset dpms $STANDBY $SUSPEND $OFF" 2>> $OUTPUT | grep -q display 2>&1 ; then
  54.                     log "VERBOSE" "Unable to set DPMS timeouts: X is not running on $DISPLAY"
  55.                 else 
  56.                     log "VERBOSE" "Set screen $DISPLAY for the user $XUSER to standby in $STANDBY s, suspend in $SUSPEND s, powerdown in $OFF s using Xauthority $XAUTHORITY"
  57.                 fi
  58.             else
  59.                 log "VERBOSE" "Unable to determine Xauthority for display :$displaynum."
  60.             fi
  61.         fi
  62.     done
  63. else
  64.     log "VERBOSE" "CONTROL_DPMS_STANDBY is disabled, skipping..."
  65. fi
  66.  
  67.